﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CvModel;
using System.Data.Entity.Migrations;
using System.Data.SqlClient;
using System.Data;

namespace DAL
{
    public class CvDB
    {
        private static CvModelContainer _context = new CvModelContainer();

        //CREATE
        public static int CreateCV(Cv cv)
        {
            try
            {
                var query = _context.Cvs.Add(cv);
                return _context.SaveChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }
        //READ
        public static Cv GetCv(int cvId)
        {
            try
            {
                return _context.Cvs.Where(c => c.CvId == cvId).ToList().First();
            }
            catch (Exception)
            {

                throw;
            }
        }
        //UPDATE
        public static int UpdateCV(Cv cv)
        {
            try
            {
                _context.Cvs.AddOrUpdate(cv);
                return _context.SaveChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }
        //DELETE
        public static int DeleteCV(int cvId)
        {
            try
            {
                var query =
                    (from c in _context.Cvs
                     where c.CvId == cvId
                     select c).Single();

                _context.Cvs.Remove(query);

                return _context.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
